package com.mchsdk.paysdk.http.process;

import android.os.Handler;
import android.text.TextUtils;

import com.lidroid.xutils.http.RequestParams;
import com.mchsdk.paysdk.bean.ChannelAndGameInfo;
import com.mchsdk.paysdk.bean.PersonalCenterModel;
import com.mchsdk.paysdk.config.MCHConstant;
import com.mchsdk.paysdk.http.request.ChangePlayerLevelRequest;
import com.mchsdk.paysdk.http.request.LoginRequest;
import com.mchsdk.paysdk.utils.MCLog;
import com.mchsdk.paysdk.utils.RequestParamUtil;

import org.apache.http.entity.StringEntity;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

public class ChangePlayerLevelProcess {

	private static final String TAG = "ChangePlayerLevelProcess";
	private int type;
	private String role_level;

	public void setRole_level(String role_level) {
		this.role_level = role_level;
	}

	public void setType(int type) {
		this.type = type;
	}

	public void post(Handler handler) {
		if (null == handler) {
			MCLog.e(TAG, "fun#post handler is null");
			return;
		}
		Map<String, String> map = new HashMap<String, String>();
	//	map.put("sdk_version", "0");//表示android发送的请求，固定值0
		map.put("user_id", PersonalCenterModel.getInstance().getUserId());
		map.put("game_id", ChannelAndGameInfo.getInstance().getGameId());
		map.put("type", type+"");
		map.put("role_level", role_level);

		String param = RequestParamUtil.getRequestParamString(map);
		if (TextUtils.isEmpty(param)) {
			MCLog.e(TAG, "fun#post param is null");
			return;
		}
		RequestParams params = new RequestParams();
		MCLog.w(TAG, "fun#post postSign:" + map.toString());
		try {
			params.setBodyEntity(new StringEntity(param.toString()));
		} catch (UnsupportedEncodingException e) {
			params = null;
			MCLog.e(TAG, "fun#post UnsupportedEncodingException:" + e);
		}

		if (null != params) {
			ChangePlayerLevelRequest changePlayerLevelRequest = new ChangePlayerLevelRequest(handler, role_level);
			changePlayerLevelRequest.post(MCHConstant.getInstance().getChangeLevelNameUrl(), params);
		} else {
			MCLog.e(TAG, "fun#post RequestParams is null");
		}
	}

}
